﻿<%@ Page Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true"
    CodeBehind="Add.aspx.cs" Inherits="jnlamp.Web.alarminfo.Add" Title="增加页" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <style type="text/css">
        .fitem label {
            width: 100px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="p" class="easyui-panel" data-options="tools:'#p_buttons'" style="overflow: auto; width: 100%; ">
        <%--<div id="dlg" class="easyui-dialog" style="width: 350px; height: auto; padding: 10px 20px"
            data-options="closed:true,buttons:'#dlg-buttons',shadow:false">--%>
        <form id="fmalarm" method="post" >
            <div class="fitem">
                <label>类别：</label>
                <input id="asid" name="asid" class="easyui-combobox" style="width: 200px;" />
                <input name="fid" id="fid" type="hidden" />
                <input name="fsid" id="fsid" type="hidden" />
                <input name="atype" id="atype" type="hidden" />
            </div>
            <div class="fitem" id="isfirst" style="display: none;">
                <label>是否首次</label>
                <input type="checkbox" id="myisfirst" checked="checked" onclick="getone()" />
            </div>
            <div class="fitem">
                <label>级别：</label>
                <span id="mylevel"></span>
                <input name="alevel" id="alevel" type="hidden" />
            </div>
            <div class="fitem" style=" height:80px;">
                <label>信息：</label>
                <span id="myinfo"></span>
                <input name="ainfo" id="ainfo" type="hidden" />
            </div>
            <div class="fitem">
                <label>发送人员：</label>
                <input name="uid" id="uid" />
            </div>
        </form>
        <div id="p_buttons" style="margin-bottom: 5px; margin-right: 10px; text-align: right;">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="savealarm()">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#adlg').dialog('close')">关闭</a>
        </div>
    </div>

    <script type="text/javascript">
        var pets = "";
        var stage = "";
        var stati = "";
        var num = "";
        var address = "";
        var inputtime = "";
        var areaName = "";
        var isone = "";
        var level = "";
        var fsid = "";
        var info = "";
        //参考值
        var gl = "";
        var gc = "";
        var gu = "";
        var alevel = "";
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
        $(function () {
            Init();
        });
        function Init() {
            $("#fid").val(pid);
            $("#atype").val(atype);
            //获取当前行的有用数据（名，单位，数量，阶段）
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=forest&pid=" + pid + "&atype=" + atype,
                success: function aa(data) {
                    if (data != "") {
                        pets = data[0].pet;
                        //alert(pets);
                        stage = data[0].stage;
                        stati = data[0].stati;
                        num = data[0].num;
                        address = data[0].address;
                        inputtime = data[0].inputtime;
                    }
                }
            });
            //类别
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    areaName = data[0].province + data[0].city + data[0].county;
                    alevel = data[0].level;
                    if (alevel == "-1") alevel = "3";
                    var encode = encodeURI(encodeURI(areaName));
                    $('#asid').combobox({
                        url: "../areastanderdinfo/GetAreaStanderd.ashx?action=ddllistmy&aname='" + encode + "'",
                        valueField: 'asid',
                        textField: 'sname',
                        panelHeight: 'auto',
                        editable: false,
                        onSelect: function (record) {
                            if (record) {
                                if (record.sname == '检疫性有害生物') {
                                    isone = "yes";
                                    $('#isfirst').show();
                                    //$('#myisfirt').attr("checked", "checked");
                                    getone();
                                }
                                else {
                                    isone = "";
                                    $('#isfirst').hide();
                                    $('#myisfirt').removeAttr("checked");
                                    //计算级别
                                    getlevel();
                                }
                            }
                        },
                        onLoadSuccess: function () {
                            var data = $('#asid').combobox('getData');
                            if (data.length > 0)
                                $("#asid").combobox('select', data[0].caid);
                        }
                    });
                    //首次出现
                }
            });
        }
        function getone()
        {
            
            if ($("#myisfirst").is(':checked')) {
                level = "一级";
                gl = "";
                gc = "";
                gu = "";
                $("#mylevel").text("一级" + "(首次出现)");
                $("#alevel").val("一级");
                $("#fsid").val("0");
                //根据 地区+虫子+类型+发生几级+时间。
                info = "根据" + areaName + "地区的有害生物" + pets + "，按类型" + $("#asid").combobox('getText') + "，因首次发生预警级别为一级，发生时间是：" + inputtime;
                $("#myinfo").text(info);
                $("#ainfo").val(info);
                //获取人员信息
                $('#uid').combotree({
                    url: '../userinfo/GetUser.ashx?action=querymypost&level=' + level,
                    multiple: true,
                    width: 300
                });
            }
            else {
                getlevel();
            }
        }
        function getlevel() {
            var enareaName = encodeURI(encodeURI(areaName));
            var enpets = encodeURI(encodeURI(pets));
            var enstage = encodeURI(encodeURI(stage));
            var enstati = encodeURI(encodeURI(stati));
            var asid = $("#asid").combobox('getValue');
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../ForestStandard/Getstandard.ashx?action=getlevel&aname=" + enareaName + "&pets=" + enpets + "&stage=" + enstage + "&stati=" + enstati + "&num=" + num + "&asid=" + asid,
                success: function aa(data) {
                    if (data != "") {
                        fsid = data[0].fsid;
                        level = data[0].level;
                        gl = data[0].l;
                        gc = data[0].c;
                        gu = data[0].u;
                        $("#mylevel").text(level + "(" + gl + "-" + gc + "-" + gu + ")");
                        $("#alevel").val(level);
                        $("#fsid").val(fsid);
                        //根据 地区+虫子+类型+发生几级+时间。
                        if (level != "没找到相关标准")
                        {
                            info = "根据" + areaName + "地区的有害生物" + pets + "，按类型" + $("#asid").combobox('getText') + "发生了" + level + "预警，发生时间是：" + inputtime;
                            $("#myinfo").text(info);
                            $("#ainfo").val(info);
                            //获取人员信息
                            $('#uid').combotree({
                                url: '../userinfo/GetUser.ashx?action=querymypost&level=' + level,
                                multiple: true,
                                width: 300
                            });
                        }
                        else {
                            $("#myinfo").text("");
                            $("#ainfo").val("");
                            $('#uid').combotree('reset');
                            $('#uid').combotree('loadData', []);
                            $.messager.alert("提示", "没有找到相关标准，不能定义预警级别。", "info");

                        }
                        
                    }
                }
            });

        }
        function savealarm() {

            var f = $('#fmalarm');
            if (level != "没找到相关标准") {
                f.form('submit', {
                    url: "../alarminfo/GetAlarm.ashx?action=add",
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#adlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
            else {
                $.messager.alert("提示", "没有找到相关标准，不能定义预警级别。", "info");
            }
        }

    </script>
</asp:Content>
